{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.empty((100, 2))\n",
    "X[:,0] = np.random.uniform(0., 100, size=100)\n",
    "X[:,1] = 0.75 * X[:, 0] + 3. + np.random.normal(0, 10., size=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAaBklEQVR4nO3df5BdZX3H8fc3mwU2WF2Q6MCGNHGGiYIUY3eQmo5jgxYRCxmKCrWWTunkH1uRMtFgnQFmbImDinbGwcmAllaHgMgEFEfqEJxOmTE1MSBEpFBQyBIFK4vWrGUTvv3jnptsbs6995x7fj7nfF4zmd179u49z70n+73P/T7f53nM3RERkfAsqroBIiIyGgVwEZFAKYCLiARKAVxEJFAK4CIigVpc5slOOOEEX7FiRZmnFBEJ3s6dO3/h7kt7j5cawFesWMGOHTvKPKWISPDM7Kdxx5VCEREJlAK4iEigFMBFRAKlAC4iEigFcBGRQJVahSIiErqtu2a4/t7HeHZ2jpMmJ9hwzirWrZ6qpC0K4CIiCW3dNcNVdz7M3PwBAGZm57jqzocBKgniSqGIiCR0/b2PHQzeXXPzB7j+3scqaY964CLSOqOmQZ6dnUt1vGjqgYtIq3TTIDOzcziH0iBbd80M/d2TJidSHS+aAriItEqWNMiGc1YxMT522LGJ8TE2nLMq1zYmlSiAm9kVZrbbzB4xs1vN7BgzW2lm283scTO7zcyOKrqxIiJZZUmD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uB54MtR6ugmMzuWhl9vd58BPg08TSdwvwjspPnXe6F+13ikeFfnAG4xxxpd82hmrwC+DnzE3X9VdXuKZmbvAZ5z950LD8fctWnXfTHwZuBGd18N/IaGpUviRPneC4CVwEnAsXRSB72adr2TGOn/fZ0D+B7g5AW3lwHPVtSWwpnZOJ3g/VV3vzM6/PPux6jo63NVta8ga4DzzewndFJka+n0yCejj9jQzOu+B9jj7tuj23fQCehNv97vAJ5y9+fdfR64E3grzb/eC/W7xiPFuzoH8O8Dp0Qj1EfRGey4u+I2FSLK+94MPOrun13wo7uBS6PvLwXuKrttRXL3q9x9mbuvoHN9t7n7B4D7gYuiuzXxef8MeMbMVkWHzgZ+RMOvN53UyVlmtiT6P9993o2+3j36XeO7gb+IqlHOAl7sploGcvfa/gPeDfwX8N/A31fdngKf5x/S+bj0Q+DB6N+76eSD7wMej74eX3VbC3wN3g58M/r+dcB/Ak8AXwOOrrp9BTzfNwE7omu+FTiuDdcbuBb4MfAI8K/A0U293sCtdHL983R62Jf1u8Z0UihfiGLdw3QqdYaeQ1PpRUQCVecUioiIDKAALiISKAVwEZFAKYCLiARKAVxEJFAK4CIigVIAFxEJ1P8DrziAm24ySiMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[:,0], X[:,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### demean"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def demean(X):\n",
    "    return X - np.mean(X, axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_demean = demean(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0K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whc4u6/BXYCH0qqbC4D/tA/zY2BmV0O3AhscPdjAy/tBK4xs1eb2Qp6C88/CTHGCvwUWJlUWryK3gLzzsBjqkSSh/4G8KS7f37gpZ3AdcnP1wH31z22Krn7Vndfkvw9XwPscvdrgUeA9yZva8xxayYf1gPAe+gtPB4DPhx2OKX7MvBq4KHkLGaPu3/U3Q+Y2b3Az+mlcW5w91MBx1kadz9pZh8DHgQmgG+6+4HAw6rKWuCDwH4zezx57iZgG3CvmV1Pr5rsfYHGV7cbgbvN7FZgH70vwODU1kBEJGJK14iIRExBXkQkYgryIiIRU5AXEYmYgryISMQU5EVEIqYgLyISsf8HVCaUBTMDahkAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X_demean[:,0], X_demean[:,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 梯度上升法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(w, X):\n",
    "    return np.sum((X.dot(w)**2)) / len(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "def df_math(w, X):\n",
    "    return X.T.dot(X.dot(w)) * 2. / len(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "def df_debug(w, X, epsilon=0.0001):\n",
    "    # epsilon取值比较小，因为w是方向向量，它的每个维度都很小，所以epsilon也要取很小的值\n",
    "    res = np.empty(len(w))\n",
    "    for i in range(len(w)):\n",
    "        w_1 = w.copy()\n",
    "        w_1[i] += epsilon\n",
    "        w_2 = w.copy()\n",
    "        w_2[i] -= epsilon\n",
    "        res[i] = (f(w_1, X) - f(w_2, X)) / (2 * epsilon)\n",
    "    return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 把向量单位化\n",
    "def direction(w):\n",
    "    return w / np.linalg.norm(w)\n",
    "\n",
    "def gradient_ascent(df, X, initial_w, eta, n_iters=1e4, epsilon=1e-8):\n",
    "    w = direction(initial_w)\n",
    "    cur_iter = 0\n",
    "    while cur_iter < n_iters:\n",
    "        gradient = df(w, X)\n",
    "        last_w = w\n",
    "        w = w + eta * gradient\n",
    "        w = direction(w)\n",
    "        if(abs(f(w, X)) - abs(f(last_w, X)) < epsilon):\n",
    "           break\n",
    "        cur_iter += 1\n",
    "    return w"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果每次计算出w后不做单位化的工作，算法也可以工作，因为w本身也是代方向的。\n",
    "但这样会导致搜索过程不顺畅。\n",
    "因为如果不做单位化，w应该是公式要求的w偏大的，这就要求eta值非常小。\n",
    "而eta值小又会导致循环次数非常多，性能就会下降。\n",
    "因此遵循公式的假设条件，每次都让w成为方向向量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "initial_w = np.random.random(X.shape[1]) # 不能是零向量。因为w=0本身也是在极值点上，是极小值点，此时梯度也会0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "eta = 0.001"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "不能使用StandardScaler标准化数据。\n",
    "因为本算法的目标就是让方差最大。\n",
    "一但对数据做了标准化，样本的方差就肯定是1了，不存在方差最大值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.7937871 , 0.60819573])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gradient_ascent(df_debug, X_demean, initial_w, eta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = gradient_ascent(df_math, X_demean, initial_w, eta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAD4CAYAAAAJmJb0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAdo0lEQVR4nO3df7BdVX338feXS8A4VO+DCQVvEpNWJhUMJfQOIBk7GpHw6wl3MqBBtEy1jc4EBy2NJPyo0GJzER9+VLBCER+YZBp+aQBFEQhtx2CAGxJII+ATQSKXKKklVk2EJHyfP/a5yclln3PPOfv3Op/XTIZ7zj5n77XP5X7P2t/1XWubuyMiImHar+gGiIhIdhTkRUQCpiAvIhIwBXkRkYApyIuIBGz/ohtQb8KECT516tSimyEiUilr1679L3efGLetVEF+6tSpDA0NFd0MEZFKMbMXG21TukZEJGAK8iIiAVOQFxEJmIK8iEjAFORFRAKWWnWNmfUAQ8Cwu59uZtOAFcDBwJPAJ9z99bSOJyJSRivXDXPVA8/x8rYdvLN3PIvmTGdgZl9h7UmzJ38+8Ezd4yuBa9z9cOBV4FMpHktEpHRWrhtmybc2MLxtBw4Mb9vBkm9tYOW64cLalEqQN7NJwGnAzbXHBswG7qq95FZgII1jiYiU1VUPPMeOnbv3eW7Hzt1c9cBzBbUovXTNtcAXgD+oPX4HsM3dd9UevwTEXq+Y2QJgAcCUKVNSao6ISOc6Tbm8vG1HW8/nIXFP3sxOB15x97X1T8e8NPbuJO5+k7v3u3v/xImxs3JFRHKTJOXyzt7xbT2fhzTSNbOAuWb2M6KB1tlEPfteMxu5UpgEvJzCsUREMpUk5bJoznTGj+vZ57nx43pYNGd6qm1sR+Ig7+5L3H2Su08F5gOr3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UB/y87vFLtedC9Enge7WfQz7vkM+tITObCswEHgP+0N23QPRFABxSXMsycy1Rp+2N2uN3ANvqOjWl+b3rzlApMbOHgENjNl0MXAScFPe2mOcqVdPa7Lzd/Z7aay4murRfPvK2mNdX6rybCPncYpnZQcDdwOfc/X+iTm24zOx04BV3X2tmHxh5Oualpfi9K8inxN1PjHvezGYA04Cnav/zTwKeNLNjib7tJ9e9fBLwcsZNTVWj8x5hZucCpwMf8r2TMip/3k2EfG5vYmbjiAL8cnf/Vu3pX5rZYe6+pZZ+fKW4FmZiFjDXzE4F3gK8jahn32tm+9d686X5vStdkzF33+Duh7j7VHefShQEjnH3XwD3An9Rq7I5Hvj1yGVuCMzsZOBCYK67b6/bdC8w38wONLNpRAPPjxfRxgw8ARxeq7Q4gGiA+d6C25SJWh76G8Az7n513aZ7gXNrP58L3JN327Lk7kvcfVLt73k+sMrdzwEeAc6svaw0562efLHuB04lGnjcDvxlsc1J3fXAgcCDtauYNe7+GXffaGZ3AD8mSuMsdPfdBbYzNe6+y8zOAx4AeoBb3H1jwc3KyizgE8AGM1tfe+4iYBC4w8w+RVRNdlZB7cvbhcAKM7sCWEf0BVg4LWsgIhIwpWtERAKmIC8iEjAFeRGRgCnIi4gETEFeRCRgCvIiIgFTkBcRCdj/BwpZihlnkwkLAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X_demean[:, 0], X_demean[:, 1])\n",
    "plt.plot([0, w[0]*30], [0, w[1]*30], color='r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2 = np.empty((100, 2))\n",
    "X2[:,0] = np.random.uniform(0., 100, size=100)\n",
    "X2[:,1] = 0.75 * X2[:, 0] + 3."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {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9lCgMePk53Xuu/BD5Udqzatf0wcF3wZxvw0Gw+sCMDnARN03f30+7+XPD8ZxT+QfdR+L57g9P2Apva08JomNky4DeAh4PXBqwHDgSndON3fhfw68AjAO5+zt0n6PJrTWGwRNrM5gMLgNN04bV29+8Cr5cdrnZtNwJf9YKjQK+ZLWn0Mzs1wBM5Td/MVgBrgWPAVe5+GgohD1zZvpZF4kHgD4ELwet3AxPufj543Y3X/BpgHPiLoHT0sJldThdfa3fPA38CjFEI7jeA43T/tS6qdm2bknGdGuChpul3EzP7OeDrwKfd/d/a3Z4omdlHgTPufrz0cIVTu+2azwfeBzzk7muBN+mickklQc13I7ASWApcTqF8UK7brnU9Tfn73qkBHmqafrcwsxSF8N7n7geDw68V/0sVPJ5pV/si0A/camavUiiPrafQI+8N/psN3XnNTwIn3f1Y8PoAhUDv5mv9AeCf3H3c3aeAg8Cv0f3XuqjatW1KxnVqgCdmmn5Q+30EeMndv1jyo8PA1uD5VuBQq9sWFXe/192XufsKCtf2iLtvAZ4GbgtO66rvDODu/wKcMLNVwaFbgB/SxdeaQulknZktCP6uF79zV1/rEtWu7WHgPwejUdYBbxRLLQ1x9478A3wE+EfgZeCP2t2eCL/nf6LwX6fvA88Hfz5CoSb8FPDj4HFRu9sa0fe/Gfhm8Pwa4O+BnwBPAJe1u30RfN81wHBwvbPAwm6/1sDngR8BPwD+CrisG681sJ9CnX+KQg/77mrXlkIJ5UtBvo1QGKXT8GdqJqaISEx1aglFRETqUICLiMSUAlxEJKYU4CIiMaUAFxGJKQW4iEhMKcBFRGJKAS4iElP/H4hqUCqA+ciAAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X2[:,0], X2[:,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2_demean = demean(X2)\n",
    "w2 = gradient_ascent(df_debug, X2_demean, initial_w, eta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAD4CAYAAAAJmJb0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAfEklEQVR4nO3df5yUZb3/8deHddTFygXBxIUNv0akhEptCgc7lVKYv+Cg4g80TlKcOpSVhkpSYEcSz540TdMoLTwiP1IbyR9s/qw0QcUFV8Q1NQMGUzyy+INNl+Xz/WNm1tllZnfYuWdn5p738/Hgwc4998x93Q/0zcXnuu7rMndHRETCqU+hGyAiIvmjkBcRCTGFvIhIiCnkRURCTCEvIhJiexS6AakGDBjgQ4cOLXQzRERKyurVq19394Hp3iuqkB86dChPPvlkoZshIlJSzOzvmd5TuUZEJMQU8iIiIaaQFxEJMYW8iEiIKeRFREIssNk1ZlYBPAnE3P1EMzsIWAL0B54CznH394K6nohIGEQbYtTVN7G5uYUDqyqZOX44E0dVB/b9Qfbkvw2sT3l9BXCVuw8DtgLTAryWiEjJizbEmHVHI7HmFhyINbcw645Gog2xwK4RSMib2WDgBOBXidcGHAPcljhlITAxiGuJiIRFXX0TLa1tHY61tLZRV98U2DWCKtf8FLgQ+GDi9X5As7vvSLzeBKT994eZTQemA9TU1ATUHBGR4tO5NBNrbkl73uYMx3si5568mZ0IvObuq1MPpzk17e4k7r7A3WvdvXbgwLRP5YqIlLzZ0Ua+u3RNh9JMuqAEOLCqMrDrBtGTHwucbGbHA3sDHyLes68ysz0SvfnBwOYAriUiUnKiDTEWrdywS0/XifeIU49XRiqYOX54YNfOuSfv7rPcfbC7DwXOAB509ynAQ8CpidOmAnfmei0RkVISbYgxdv6DfGfpmvSlDOI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QU8iLiISYQl5EJMQU8iIiIaaQFxEJMYW8iEiI/X+jAG9JcR5oHgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X2_demean[:, 0], X2_demean[:, 1])\n",
    "plt.plot([0, w2[0]*30], [0, w2[1]*30], color='r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
